package cn.com.nes.site.config;

import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableDubbo
public class DubboConfig {

    @Value("${dubbo.registry.address}")
    private String address;

    @Value("${dubbo.registry.register-mode}")
    private String registerMode;

    @Value("${dubbo.application.name}")
    private String applicationName;

    @Value("${dubbo.application.logger}")
    private String logger;

    @Bean
    public RegistryConfig registryConfig() {
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setAddress(address);
        registryConfig.setRegisterMode(registerMode);
        return registryConfig;
    }

    @Bean
    public ApplicationConfig applicationConfig() {
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName(applicationName);
        applicationConfig.setLogger(logger);
        return applicationConfig;
    }
}
